package com.group3.merchant.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.group3.entity.Dish;
import com.group3.entity.DishType;
import com.group3.merchant.dao.IDishTypeDao;
import com.group3.merchant.utils.DbUtils;

public class DishTypeDaoImpl implements IDishTypeDao{

	
	@Override
	public List<DishType> queryByAll() {
		String sql = "select * from dishtype order by dtid";
		List<DishType> list = new ArrayList<DishType>();
		Connection conn = DbUtils.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				DishType dishType = new DishType();
				dishType.setpId(rs.getString(1));
				dishType.setPname(rs.getString(2));
				list.add(dishType);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DbUtils.free(conn, ps, rs);
		}
		return list;
	}
}
